2024-04-29
R Markdown makes it easy to turn a document of notes into different output formats including presentations.
… I might start to collect some notes on “Presentations with R Markdown” in a simple R Markdown document.
I want to include some references and start with a simple document with the following YAML header:
---
title: "Presentations with R Markdown"
subtitle: "Some examples"
author: Stefan Daume
date: "2024-04-29"
output:
bookdown::html_document2:
theme: paper
always_allow_html: true
bibliography: references.bib
link-citations: no
---
Using knitr (e.g. the “Knit” button in RStudio) renders this document as an HTML page.
Which would look like that:
As with any R Markdown document embedded R code chunks will be evaluated and included in the rendered document. For example:
summary(cars)
## speed dist ## Min. : 4.0 Min. : 2.00 ## 1st Qu.:12.0 1st Qu.: 26.00 ## Median :15.0 Median : 36.00 ## Mean :15.4 Mean : 42.98 ## 3rd Qu.:19.0 3rd Qu.: 56.00 ## Max. :25.0 Max. :120.00
Or a plot:
plot(pressure)
Consult the R Markdown book (Xie, Allaire, and Grolemund 2023) for more options.
Including this citation demonstrates how dynamic references and bibliographies can be included in any R Markdown output format. Check the “References” section at the end of the document.
By changing the output format in the YAML header we can turn the initial document into a presentation.
---
title: "Presentations with R Markdown"
subtitle: "Some examples"
author: Stefan Daume
date: "2024-04-29"
output:
ioslides_presentation:
widescreen: true
always_allow_html: true
bibliography: references.bib
link-citations: no
---
ioslides is only one of several supported HTML presentation formats.
In most supported HTML presentation formats slides headers of type # and ## are translated in individual slides with the header text as slide title.
Using --- creates a slide without a title.
Most HTML presentation output formats support useful features like presenter mode out of the box. This presentation in presenter mode:
https://sdaume.github.io/srccoders/rmarkdown_presentations.html?presentme=true
Check the R Markdown book (Xie, Allaire, and Grolemund 2023) for more features such as incremental display of content, custom CSS, templates etc.
The generated HTML presentation (or any HTML document) can be hosted online via GitHub pages.
This presentation is at: https://sdaume.github.io/srccoders/rmarkdown_presentations.html
pandocThe ‘heavy lifting’ of document transformations from R Markdown is enabled with pandoc (https://pandoc.org/).
Using pandoc may offer useful additional options when converting documents.
An alternative approach to creating presentations from R Markdown and using pandoc directly is documented here: https://github.com/sdaume/rmarkdown-presentation-template (slightly outdated now)
The referenced example creates a HTML presentation based on the reveal.js framework, starting with R Markdown it uses pandoc to create presentations like this.
It is versatile, offers different plugins and makes it possible to include advanced visualizations such as this
Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2023. R Markdown: The Definitive Guide.